//
//  HomeViewCell.swift
//  DKE-Album
//
//  Created by 杨东宝 on 2020/6/14.
//  Copyright © 2020 杨东宝. All rights reserved.
//

import UIKit

class HomeViewCell: UITableViewCell {
    var _homeMoel:HomeModel?
    
    //MARK:- 改计划按钮
    lazy var changeBtn: UIButton = {
        
        let btn =  UIButton.init(type: .custom)
        btn.setTitle("改计划", for: .normal)
        btn.setTitleColor(hexColor(0x999999,0xA7A7B3), for: .normal)
        btn.titleLabel?.font = DIMENSION_FONT_OF_SIZE(12)
        btn.setBackgroundColor(HexRGB(0xD8D8D8), forState: .normal)
        btn.layer.cornerRadius = DIMENSION_VALUE(9)
        btn.layer.masksToBounds = true
        btn.layer.borderColor = HexRGB(0x979797).cgColor
        btn.layer.borderWidth = 0.5
        btn.addTarget(self, action: #selector(changePlan(_ : )), for: .touchUpInside)
        contentView.addSubview(btn)
        return btn
        
    }()
    
    //MARK:-已坚持
    lazy var label1: UILabel = {
        let label = UILabel()
        label.text = "已坚持"
        label.font = DIMENSION_FONT_OF_SIZE(14)
        label.textColor = hexColor(0x999999,0xA7A7B3)
        contentView.addSubview(label)
        return label
    }()
    //MARK:-已坚持 - days
    lazy var label1Day: UILabel = {
        let label = UILabel()
        contentView.addSubview(label)
        return label
    }()
    //MARK:-计划详情
    lazy var label1Detail: UILabel = {
        let label = UILabel()
        label.font = DIMENSION_FONT_OF_SIZE(12)
        label.textColor = hexColor(0x999999,0xA7A7B3)
        contentView.addSubview(label)
        return label
    }()
    //MARK:-今日任务
    lazy var label2: UILabel = {
        let label = UILabel()
        label.text = "今日任务"
        label.font = DIMENSION_FONT_OF_SIZE(14)
        label.textColor = hexColor(0x999999,0xA7A7B3)
        contentView.addSubview(label)
        return label
    }()
    //MARK:-今日任务 - 个数
    lazy var label2Count: UILabel = {
        let label = UILabel()
        
        let prefix = "100"
        let suffix = "个"
        
        let string = prefix + suffix
        let myAttribute = [NSAttributedString.Key.foregroundColor: hexColor(0x999999,0xA7A7B3),
                           NSAttributedString.Key.font: DIMENSION_BoldFONT_OF_SIZE(42)] as [NSAttributedString.Key : Any]
        let redAttribute = [NSAttributedString.Key.foregroundColor:hexColor(0x999999,0xA7A7B3),
                            NSAttributedString.Key.font: DIMENSION_BoldFONT_OF_SIZE(14)] as [NSAttributedString.Key : Any]
        let attString = NSMutableAttributedString(string: string)
        attString.addAttributes(myAttribute, range:NSRange.init(location: 0, length: prefix.count))
        attString.addAttributes(redAttribute, range: NSRange.init(location: prefix.count, length: suffix.count))
        label.attributedText = attString
        contentView.addSubview(label)
        return label
    }()
    //MARK:- 今日任务详情
    lazy var label2Detail: UILabel = {
        let label = UILabel()
        label.text = "新词50/复习词50"
        label.font = DIMENSION_FONT_OF_SIZE(12)
        label.textColor = hexColor(0x999999,0xA7A7B3)
        contentView.addSubview(label)
        return label
    }()
    
    //MARK:- 中间背景
    lazy var centerView: UIView = {
        let centerView = UIView()
        centerView.backgroundColor = HexRGB(0xD8D8D8)
        centerView.layer.cornerRadius = DIMENSION_VALUE(5)
        centerView.layer.masksToBounds = true
        contentView.addSubview(centerView)
        return centerView
    }()
    
    //MARK:逃坑英语专属词本
    lazy var label3: UILabel = {
        let label = UILabel()
        label.text = "逃坑英语专属词本"
        label.font = DIMENSION_FONT_OF_SIZE(19)
        label.textColor = hexColor(0x999999,0xA7A7B3)
        centerView.addSubview(label)
        return label
    }()
    //MARK:已学完
    lazy var label4: UILabel = {
        let label = UILabel()
        label.text = "已学完 11.1%"
        label.font = DIMENSION_FONT_OF_SIZE(12)
        label.textColor = hexColor(0x999999,0xA7A7B3)
        centerView.addSubview(label)
        return label
    }()
    //MARK:总数量
    lazy var label5: UILabel = {
        let label = UILabel()
        label.text = "500/4500词"
        label.font = DIMENSION_FONT_OF_SIZE(12)
        label.textColor = hexColor(0x999999,0xA7A7B3)
        centerView.addSubview(label)
        return label
    }()
    
    //MARK: 词本按钮
    lazy var cibenBtn: UIButton = {
        let btn =  UIButton.init(type: .custom)
        btn.setTitle("词本", for: .normal)
        btn.setTitleColor(hexColor(0x666666,0xA7A7B3), for: .normal)
        btn.titleLabel?.font = DIMENSION_FONT_OF_SIZE(14)
        btn.setBackgroundColor(HexRGB(0xB5B5B5), forState: .normal)
        btn.addTarget(self, action: #selector(wordBookClick), for: .touchUpInside)
        btn.layer.cornerRadius = DIMENSION_VALUE(10)
        btn.layer.masksToBounds = true
        centerView.addSubview(btn)
        return btn
    }()
    
    lazy var progressView: UIProgressView = {
        let  progressView = UIProgressView(progressViewStyle: .default)
        progressView.progress = 0.4
        progressView.progressTintColor = HexRGB(0x9A9A9A) //进度颜色
        progressView.trackTintColor = HexRGB(0xB5B5B5) //剩余进度颜色
        centerView.addSubview(progressView)
        return progressView
    }()
    
    //MARK:- 打印词本
    lazy var printedWordBtn: UIButton = {
        
        let btn =  UIButton.init(type: .custom)
        btn.setTitle("打印词本", for: .normal)
        btn.setTitleColor(hexColor(0x666666,0xA7A7B3), for: .normal)
        btn.titleLabel?.font = DIMENSION_FONT_OF_SIZE(14)
        btn.addTarget(self, action: #selector(printWordBook(_ : )), for: .touchUpInside)
        contentView.addSubview(btn)
        return btn
    }()
    
    //MARK:- 开始背单词
    lazy var beginWordBtn: UIButton = {
        
        let btn =  UIButton.init(type: .custom)
        btn.setTitle("开始背单词！", for: .normal)
        btn.setTitleColor(HexRGB(0xffffff), for: .normal)
        btn.titleLabel?.font = DIMENSION_FONT_OF_SIZE(14)
        btn.setBackgroundColor(HexRGB(0x8CC56C), forState: .normal)
        btn.layer.cornerRadius = DIMENSION_VALUE(24)
        btn.layer.masksToBounds = true
        btn.addTarget(self, action: #selector(beganToRecite(_ : )), for: .touchUpInside)
        contentView.addSubview(btn)
        return btn
        
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = hexColor(0xFAF8EF, 0x2B2A3A)
        initSubView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initSubView() {
        
        label1.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(50))
            make.top.equalTo(DIMENSION_VALUE(79))
            make.height.equalTo(DIMENSION_VALUE(20))
        }
        label1Day.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(50))
            make.top.equalTo(label1.snp_bottom).offset(DIMENSION_VALUE(15))
            make.height.equalTo(DIMENSION_VALUE(59))
        }
        label1Detail.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(50))
            make.top.equalTo(label1Day.snp_bottom).offset(DIMENSION_VALUE(10))
            make.height.equalTo(DIMENSION_VALUE(16.5))
        }
        label2.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(238))
            make.top.equalTo(label1.snp_top)
            make.height.equalTo(DIMENSION_VALUE(20))
        }
        label2Count.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(238))
            make.top.equalTo(label1Day.snp_top)
            make.height.equalTo(DIMENSION_VALUE(59))
        }
        label2Detail.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(238))
            make.top.equalTo(label1Detail.snp_top)
            make.height.equalTo(DIMENSION_VALUE(16.5))
        }
        changeBtn.snp.makeConstraints { (make) in
            make.left.equalTo(label1Detail.snp_right).offset(DIMENSION_VALUE(6))
            make.width.equalTo(DIMENSION_VALUE(50))
            make.height.equalTo(DIMENSION_VALUE(18))
            make.centerY.equalTo(label1Detail.snp_centerY)
        }
        
        centerView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(27.5))
            make.top.equalTo(changeBtn.snp_bottom).offset(DIMENSION_VALUE(50))
            make.height.equalTo(DIMENSION_VALUE(100))
            make.width.equalTo(DIMENSION_VALUE(320))
        }
        
        label3.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(15))
            make.top.equalToSuperview().offset(DIMENSION_VALUE(14))
            make.height.equalTo(DIMENSION_VALUE(25))
        }
        
        cibenBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-15))
            make.centerY.equalTo(label3.snp_centerY)
            make.height.equalTo(DIMENSION_VALUE(20))
            make.width.equalTo(DIMENSION_VALUE(48))
            
        }
        
        label4.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(15))
            make.top.equalTo(label3.snp_bottom).offset(DIMENSION_VALUE(19))
            make.height.equalTo(DIMENSION_VALUE(16.5))
            
        }
        
        label5.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-15))
            make.top.equalTo(label4.snp_top)
            make.height.equalTo(DIMENSION_VALUE(16.5))
            
        }
        progressView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(15))
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-15))
            make.top.equalTo(label5.snp_bottom).offset(DIMENSION_VALUE(6))
            make.height.equalTo(DIMENSION_VALUE(5))
            
        }
        printedWordBtn.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView.snp_centerX)
            make.top.equalTo(centerView.snp_bottom).offset(DIMENSION_VALUE(10))
            make.height.equalTo(DIMENSION_VALUE(20))
            
        }
        beginWordBtn.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(27.5))
            make.top.equalTo(printedWordBtn.snp_bottom).offset(DIMENSION_VALUE(61))
            make.height.equalTo(DIMENSION_VALUE(48))
            make.width.equalTo(DIMENSION_VALUE(320))
            make.bottom.equalTo(contentView.snp_bottom).offset(DIMENSION_VALUE(-60))
        }
    }
    
}
extension HomeViewCell{
    
    //MARK:-日历点击方法
    @objc func calendarClick(_ btn :UIButton) {
    }
    //MARK:-打印词本点击方法
    @objc func printWordBook(_ btn :UIButton) {
    }
    //MARK:-开始背单词点击方法
    @objc func beganToRecite(_ btn :UIButton) {
        
    }
    func start() {
        
        
    }
    //MARK:-修改计划按钮
    @objc func changePlan(_ btn :UIButton) {
       
    }
    
    @objc func wordBookClick() {
        appManger.mainTabbar?.setTabbarWithIndex(index: 1)
    }
    
}
//MARK:-数据赋值
extension HomeViewCell{
    var model:HomeModel{
        set{
            _homeMoel = newValue
            self.setModel(model: _homeMoel!)
        }
        get{
            return _homeMoel!
        }
    }
    func setModel(model:HomeModel) {

    }
}
